package 题目集.日期问题;

import java.util.Scanner;

public class 回文日期 {
    static int[] months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public static int getDay(int y, int m) {
        if (m == 2) {
            return isLeap(y) ? 29 : 28;
        }
        return months[m];
    }

    public static boolean isLeap(int y) {
        return (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0);
    }

    static int y, m, d;

    public static void next() {
        if (d >= getDay(y, m)) {
            if (m >= 12) {
                m = 0;
                y++;
            }
            d = 0;
            m++;
        }
        d++;
    }

    public static boolean check1(String str) {
        int l = 0, r = str.length() - 1;
        while (l < r) {
            if (str.charAt(l++) != str.charAt(r--)) return false;
        }
        return true;
    }

    public static boolean check2(String str) {
        char A=str.charAt(0),B=str.charAt(1);
        if (A==B) return false;
        String s=""+A+B+A+B+B+A+B+A;
        return s.equals(str);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        y = Integer.parseInt(line.substring(0, 4));
        m = Integer.parseInt(line.substring(4, 6));
        d = Integer.parseInt(line.substring(6, 8));
        boolean flag1 = false, flag2 = false;
        while (!flag1 || !flag2) {
            next();
            String date = String.format("%04d%02d%02d", y, m, d);
            if (!flag1 && check1(date)) {
                flag1 = true;
                System.out.println(date);
            }
            if (!flag2 && check2(date)) {
                flag2 = true;
                System.out.println(date);
            }
        }
    }
}
